package com.zzyl.controller.manager;

import cn.hutool.core.bean.BeanUtil;
import com.zzyl.base.PageBean;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.dto.NursingLevelPageQueryDto;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/nursingLevel")
@Api(tags = "护理等级管理")
@Slf4j
public class NursingLevelController {

    @Resource
    private NursingLevelService nursingLevelService;

    /**
     * 查询所有护理等级
     * @return List<NursingLevelVo> 护理等级VO集合
     */
    @ApiOperation("查询所有护理等级")
    @GetMapping
    ResponseResult<List<NursingLevelVo>> getNursingLevelVoList() {
        List<NursingLevelVo> list = nursingLevelService.list();
        return ResponseResult.success(list);
    }

    /**
     * 新增护理等级
     * @param nursingLevelDto
     * @return
     */
    @ApiOperation("新增护理等级")
    @PostMapping("/insert")
    public ResponseResult addNursingLevel(@RequestBody NursingLevelDto nursingLevelDto) {
        log.info("新增护理等级:{}", nursingLevelDto);
        nursingLevelService.addNursingLevel(nursingLevelDto);
        return ResponseResult.success();
    }

    /**
     * 条件分页查询护理等级
     * @param dto
     * @return
     */
    @ApiOperation("条件分页查询护理等级")
    @GetMapping("/listByPage")
    public ResponseResult<PageBean<NursingLevelVo>> listByPage(NursingLevelPageQueryDto dto) {
        log.info("条件分页查询护理等级:{}", dto);
        PageBean<NursingLevelVo> pageBean = nursingLevelService.listByPage(dto);
        return ResponseResult.success(pageBean);
    }

    /**
     * 根据id查询护理等级
     * @param id
     * @return
     */
    @ApiOperation("根据id查询护理等级")
    @GetMapping("/{id}")
    public ResponseResult<NursingLevelVo> getNursingLevelById(@PathVariable Long id) {
        log.info("根据id查询护理等级:{}", id);
        NursingLevelVo nursingLevelVo = nursingLevelService.getNursingLevelById(id);
        return ResponseResult.success(nursingLevelVo);
    }

    /**
     * 修改护理等级
     * @param nursingLevelDto
     * @return
     */
    @ApiOperation("修改护理等级")
    @PutMapping("/update")
    public ResponseResult updateNursingLevel(@RequestBody NursingLevelDto nursingLevelDto) {
        log.info("修改护理等级:{}", nursingLevelDto);
        nursingLevelService.updateNursingLevel(nursingLevelDto);
        return ResponseResult.success();
    }

    /**
     * 删除护理等级
     * @param id
     * @return
     */
    @ApiOperation("删除护理等级")
    @DeleteMapping("/delete/{id}")
    public ResponseResult deleteNursingLevel(@PathVariable Long id) {
        log.info("删除护理等级:{}", id);
        nursingLevelService.deleteNursingLevel(id);
        return ResponseResult.success();
    }

    /**
     * 启用禁用护理等级
     * @param id
     * @param status
     * @return
     */
    @ApiOperation("启用禁用护理等级")
    @PutMapping("/{id}/status/{status}")
    public ResponseResult enableOrDisableNursingLevel(@PathVariable Long id, @PathVariable Integer status) {
        log.info("启用禁用护理等级，id:{}，status:{}", id, status);
        nursingLevelService.enableOrDisableNursingLevel(id, status);
        return ResponseResult.success();
    }
}